
	    var count1 = 0;
		//医嘱另存为方案或者编辑
		function saveFangan(bbx01)
		{
			debugger;
			var bck01a = bck01;
			//----------------------
			var bbx1 = {};
			//bbx1.bbx01 = '0';
			bbx1.bda01 = '9';
			debugger;
			bbx1.bdo01 = $("#fangan_fenlei").attr("data-id");
			bbx1.bbx04 = new Date().getTime();//编号
			bbx1.bbx05 = $("#fangan_name").val();//
			if(!($("#fangan_fenlei").val())){
				layer.tips('请选择方案分类', '#fangan_fenlei');
				$("#save_edit_fangan").removeAttr("disabled");
				return false;
			}
			if(!bbx1.bbx05){
				layer.tips('请填写方案名称', '#fangan_name');
				$("#save_edit_fangan").removeAttr("disabled");
				return false;
			}
			bbx1.bbx06 = "";//
			bbx1.bdg02 = "";//
			bbx1.bbx08 = "";//
			bbx1.bbx09 = 0;//
			bbx1.abw01 = "0";//
			bbx1.bbx11 = "1";//
			bbx1.bbx12 = "0";//
			bbx1.bbx13 = "";//
			bbx1.bbx14 = "0";//
			bbx1.bbx15 = $(".fangan_radio:checked").val();//
			bbx1.acf01 = "1";//
			bbx1.bbx17 = "1";//
			bbx1.bbx18 = "0";//
			bbx1.bbx19 = "";//
			bbx1.bbx20 = "0";//
			bbx1.bbx21 = "0";//
			bbx1.bbx30 = 0;//
			bbx1.bbx36 = 0;//
			bbx1.bbx46 = 0;//
			bbx1.bcw01 = "0";//
			bbx1.bce01 = bce01;//
			bbx1.bbx25 = "9999-12-31";//
			bbx1.acf01 = "1";//
			
			/*---------------------------------------编辑的时候传bbx01a--------------------------------*/
			if(bbx01){
				
				bbx1.bbx01 = bbx01;//
			}
			/*---------------------------------------编辑的时候传bbx01a--------------------------------*/
			
			var bdk1Arr = [];
			var bdk1 = {};
			bdk1.bdk03 = $("#fangan_name").val();//方案名称
			bdk1.bdk06 = 1;;//方案别名
			var bdk2 = {};
			bdk2.bdk03 = $("#fangan_bieming").val();//方案名称
			bdk2.bdk06 = 9;//方案别名
			bdk1Arr.push(bdk1);
			bdk1Arr.push(bdk2);
			var bef1Arr = [];
			var bar1Arr = [];
			var bar1 = {};
			bar1.bck01 = bck01;
			bar1Arr.push(bar1);
			var bef1 = [];
			// 西药
			var xiyao_tables = $(".left-content").find(".xiyao_table");
			$(xiyao_tables).each(function(x){
				debugger;
				var tableId = $(this).attr("id");
				GetBef1(tableId,bef1,x);//西药
			});
			// 中药
			debugger;
			var zhongyao_tables = $(".left-content").find(".zhongyao_table");
			$(zhongyao_tables).each(function(x,ele){
//				var tableId = $(this).attr("id");
				GetBef3(ele,bef1,x);//中药
			});
			// 检验
			var jianyan_tables = $(".left-content").find(".jianyan_table");
			$(jianyan_tables).each(function(x){
				var tableId = $(this).attr("id");
				GetBefL(tableId,bef1,x);//检验
			});
			// 检查
			var jiancha_tables = $(".left-content").find(".jiancha_table");
			$(jiancha_tables).each(function(x){
				var tableId = $(this).attr("id");
				GetBefE(tableId,bef1,x);//检查
			});
			// 手术
			var shoushu_tables = $(".left-content").find(".shoushu_table");
			$(shoushu_tables).each(function(x){
				var tableId = $(this).attr("id");
				GetBefS(tableId,bef1,x);//手术
			});
			// 治疗
			var zhiliao_tables = $(".left-content").find(".zhiliao_table");
			$(zhiliao_tables).each(function(x){
				var tableId = $(this).attr("id");
				GetBefT(tableId,bef1,x);//治疗
			});
			// 材料
			var cailiao_tables = $(".left-content").find(".cailiao_table");
			$(cailiao_tables).each(function(x){
				var tableId = $(this).attr("id");
				GetBef4(tableId,bef1,x);//材料
			});
			debugger;
			console.table(bef1);
			///////////////////////////////////////////////////////华丽的分割线
			if(bef1.length==0)
			{
				layer.msg('没有需要保存的方案，请检查！', {
					time : 2000,
					icon : 0,
					skin: 'layui-layer-msg0'
				});
				$("#save_edit_fangan").removeAttr("disabled");
			}
			else
			{
				$.ajax({
					url:kzzxUrl+"/bef1/saveBef1",
//					url:"http://192.168.1.143:8080/centerweb/cloud"+"/bef1/saveBef1",
					type: "post",
					data: {bbx1:JSON.stringify(bbx1),bdk1:JSON.stringify(bdk1Arr)
						,bef1:JSON.stringify(bef1),bar1:JSON.stringify(bar1Arr),jsessionids:$.cookie("jsessionids")},
					dataType:'text',
					timeout:1000,
					success:function(data)
					{
						debugger;
						if(data=="SUCCESS"){
							layer.msg("保存成功", {
								time : 2000,
								icon : 1,
								skin: 'layui-layer-msg1'
							});
							layer.close(saveFangan_index);
							$("#saveoredit_fangan").attr("data-bbx01","");
							$("#save_edit_fangan").removeAttr("disabled");
						}else{
							layer.msg("保存失败", {
								time : 2000,
								icon : 0,
								skin: 'layui-layer-msg0'
							});
							$("#save_edit_fangan").removeAttr("disabled");
						}
					},
					error: function(XMLHttpRequest, textStatus, errorThrown) 
					{
						$("#save_edit_fangan").removeAttr("disabled");
						if (textStatus=='timeout') {
							layer.msg('控制中心服务器连接失败！', {
								time : 2000,
								icon : 0,
								skin: 'layui-layer-msg0'
							});
						}
						else
						{
							layer.msg(textStatus, {
								time : 2000,
								icon : 2,
								skin: 'layui-layer-msg2'
							});
						}
					}
				});
			}
		}
		
		//西药
		function GetBef1(tableId,bef1,x) 
		{
			 var bck01a = bck01;
			 var rownr = 1;
			 var zuValue = 1;
			 $("#"+tableId+" tbody tr").each(function(i)
			 { 
				 var tdArr = $(this);
				 var flag = tdArr.find(".xiyao_yznr").val(); //如果医嘱内容为空，则不保存
				 if (flag != "" && flag !=undefined) 
				 {
					  var bda01 = "1";
					  var zu = tdArr.find(".xiyao_zu").text();
						 if (!zu) //同组
						 {
							 rownr++;
						 }
						 else//非同组--组号递增
						 {
							 zuValue++;
						 }
					  //给药途径
					  if (zu)
					{
						 var temp1 = configData1(tdArr,vaa01,vac01,x);//初始化公共参数
					  temp1.rownr="0";//顺序
					  temp1.bbx01c = tdArr.find(".xiyao_geiyao").find("select option:selected").attr("id");//项目ID
					  temp1.bef07 = tdArr.find(".xiyao_geiyao").find("select option:selected").text();//医嘱内容
					  temp1.bef08 = tdArr.find(".xiyao_yyts").val();//天数
					  temp1.bef09 = tdArr.find(".xiyao_dcyl").val();//剂量
					  temp1.bef11 = 1;//数量
					  temp1.bby01 = 0;//收费项目ID
					  temp1.bef13 = "";//样本部位
					  temp1.bef16 = tdArr.find(".xiyao_pinci").find("select option:selected").text();//频次
					  temp1.bef17 = tdArr.find(".xiyao_gycs").val();//频次值
					  temp1.bef20 = tdArr.find(".xiyao_zxxz").find("select option:selected").attr("id");//带药性质
					  temp1.bck01 = bck01;//给药科室
					  temp1.bef23 = 1;//滴速
					  temp1.vaf59 = zuValue;//组号
					  temp1.vaf32 = "1";//正常还是给药途径
					  temp1.bda01 = "1";
					  temp1.bef24 = tdArr.find(".xiyao_sc").val()==""?0:tdArr.find(".xiyao_sc").val();//首次
					  bef1.push(temp1);
					}
					  //正常医嘱
					  var temp2 = configData1(tdArr,vaa01,vac01,x);//初始化公共参数
					  if (zu=="") 
					  {
						  temp2.rownr=rownr;
					  }
					  else
					  {
						  temp2.rownr="1";
					  }
					  temp2.bbx01c = tdArr.find(".xiyao_yznr").next().val();//项目ID
					  temp2.bef07 = tdArr.find(".xiyao_yznr").val();//医嘱内容
					  temp2.bef08 = tdArr.find(".xiyao_yyts").val();//天数
					  temp2.bef09 = tdArr.find(".xiyao_dcyl").val();//剂量
					  temp2.bef11 = tdArr.find(".xiyao_zl").val();//数量
					  temp2.bef15 = tdArr.find(".xiyao_yszt").val();//医生嘱托
					  temp2.bby01 = tdArr.find(".xiyao_yznr").next().next().val();//收费项目ID
					  temp2.bef13 = "";//样本部位
					  temp2.bef16 = tdArr.find(".xiyao_pinci").find("select option:selected").text();//频次
					  temp2.bef17 = tdArr.find(".xiyao_gycs").val();//次数
					  temp2.bef20 = tdArr.find(".xiyao_zxxz").find("select option:selected").attr("id");//带药性质
					  temp2.bck01 = tdArr.find(".xiyao_zxks").attr("id");//执行科室
					  temp2.bef23 = tdArr.find(".xiyao_disu").val();//执行科室//滴速
					  temp2.vaf59 = zuValue;//组号
					  temp2.vaf32 = "0";//正常还是给药途径
					  temp2.bda01 = "1";
					  debugger;
					  temp2.bef24 = tdArr.find(".xiyao_sc").val()==""?0:tdArr.find(".xiyao_sc").val();//首次
					  temp2.bck01e = tdArr.find(".xiyao_gyzx select").val();//给药执行
					  bef1.push(temp2);
				 }
			 });
		}
		
		//中药
		function GetBef3(tableId,bef1,x) 
		{
			var bck01a = bck01;
			var tableObj = document.getElementById("");
			var temp1;
			count1++;
			var rownr = 0;
			var temp33 = [];
			var zhongyaoCom =$(tableId).parents(".china_medicine").find(".china_medicine_com");
			$(tableId).find("tbody tr").each(function(i)
			{ 
					var tdArr = $(this);
					var flag = tdArr.find(".zhongyao_yznr").val(); //根据医嘱内容判断是否保存
					if (flag != "" && flag !=undefined) {
						var jiaozhuVal = tdArr.find(".zhongyao_jz").find("select").val();
						var jiaozhuText;
						if(jiaozhuVal == "-1"){
							jiaozhuText="";
						}else{
							jiaozhuText = tdArr.find(".zhongyao_jz").find("select option:selected").text();
						}
						if (i==0) {
							//方剂
							temp1 = configData1(tdArr, vaa01, vac01,x);
							temp1.rownr = rownr;
							temp1.bbx01c = $(zhongyaoCom).find(".zhongyao_zyyf").find("select option:selected").val(); //用药用法的bbx01
							var jianfa = $(zhongyaoCom).find(".zhongyao_jf").find("select option:selected").text();//煎法
							
							var adviceContent = tdArr.find(".zhongyao_yznr").val()
							+ " "+jiaozhuText+";";
							temp1.bef07 = "中药1付，" + $(zhongyaoCom).find(".zhongyao_pc").find("select option:selected").text() + "，"
							+ $(zhongyaoCom).find(".zhongyao_zyyf").find("select option:selected").text() + "，" + jianfa + "："
							+ adviceContent; //医嘱内容
							temp1.bef08 = 1;//给药天数 
//							temp1.bef08 = $(zhongyaoCom).find(".zhongyao_gycs").val().trim();//给药天数 
							temp1.bef09 = tdArr.find(".zhongyao_dl").val().trim(); //单量
							temp1.bef11 = $(zhongyaoCom).find(".zhongyao_js").val().trim(); //剂数 
							temp1.bef10 = 1;
							temp1.bby01 = 0;
							temp1.bef13 = "";
							temp1.bef16 = $(zhongyaoCom).find(".zhongyao_pc").find("select option:selected").text();//频次
							temp1.bef17 = 1;
							temp1.bef20 = $(zhongyaoCom).find(".zhongyao_zxxz").find("select option:selected").attr("id");//执行性质
							temp1.bck01 = $(zhongyaoCom).find(".zhongyao_zxks select").val();//执行科室ID;
							temp1.bef23 = 0;
							temp1.vaf59 = 0;
							temp1.vaf32 = 1;
							temp1.bda01 = "8";
							temp1.bef24 = 0;
							temp1.bef15 = $(zhongyaoCom).find(".zhongyao_yszt").val(); //医生嘱托
							temp1.bck01e = $(zhongyaoCom).find(".zhongyao_gyzx select").val(); //给药执行
							}
						var adviceContent;
						if (i > 0) {
							adviceContent = tdArr.find(".zhongyao_yznr").val()+" "
							+ jiaozhuText+";";
									//+ tdArr.eq(8).find("select option:selected").text()+";";
							temp1.bef07 = temp1.bef07 + " " + adviceContent; //医嘱内容
						}
						
						//中药
						rownr++;
						var temp2 = configData1(tdArr, vaa01, vac01, x);
						temp2.rownr = rownr;
						temp2.bbx01c = tdArr.find(".zhongyao_yznr").next().val();//诊疗项目ID---
						temp2.bef07 = tdArr.find(".zhongyao_yznr").val(); //医嘱内容
						temp2.bef08 = 1;//给药天数;
						temp2.bef08 = $(zhongyaoCom).find(".zhongyao_gycs").val().trim();//给药次数;
						temp2.bef09 = tdArr.find(".zhongyao_dl").val().trim(); //单量
						temp2.bef11 = $(zhongyaoCom).find(".zhongyao_js").val(); //剂数 
						temp2.bef10 = tdArr.find(".zhongyao_zl").val().trim(); //总量
						temp2.bby01 = tdArr.find(".zhongyao_yznr").next().next().val(); //收费项目ID---
						temp2.bef13 = tdArr.find(".zhongyao_jz").find("option:selected").val();//脚注
						temp2.bef16 = $(zhongyaoCom).find(".zhongyao_pc").find("select option:selected").text();//频次
						temp2.bef17 = 1;
						temp2.bef20 = $(zhongyaoCom).find(".zhongyao_zxxz").find("select option:selected").attr("id");//执行性质
						temp2.bck01 = $(zhongyaoCom).find(".zhongyao_zxks select").val();//执行科室ID;
						temp2.bef23 = 0;
						temp2.vaf59 = 0;
						temp2.vaf32 = "0";
						temp2.bda01 = "8";
						temp2.bef24 = 0;
						temp2.bck01e = $(zhongyaoCom).find(".zhongyao_gyzx select").val(); //给药执行
						temp33.push(temp2);
					}
			});
			if (temp1 && temp1.bef07)
			{
				temp1.bef07 = temp1.bef07.substr(0, temp1.bef07.length - 1);
				bef1.push(temp1);
				rownr++;
				for(var k = 0;k<temp33.length;k++)
				{
					bef1.push(temp33[k]);
				}
				//治疗
				var temp3 = configData1("", vaa01, vac01, x);
				temp3.rownr = rownr;
				temp3.bbx01c = $(zhongyaoCom).find(".zhongyao_jf").find("select option:selected").val(); //煎法的bbx01
				temp3.bef07 = $(zhongyaoCom).find(".zhongyao_jf").find("select option:selected").text();//煎法
				temp3.bef08 = 1;
				temp3.bef09 = 1;
				temp3.bef11 = $(zhongyaoCom).find(".zhongyao_jc").val();// 煎次;
				temp3.bby01 = 0;
				temp3.bef13 = "";
				temp3.bef16 = $(zhongyaoCom).find(".zhongyao_pc").find("select option:selected").text();//频次
				temp3.bef17 = 1;
				temp3.bef20 = $(zhongyaoCom).find(".zhongyao_zxxz").find("select option:selected").attr("id");//执行性质
				temp3.bck01 = $(zhongyaoCom).find(".zhongyao_zxks select").val();//执行科室ID;
				temp3.bef23 = 0;
				temp3.vaf59 = 0;
				temp3.vaf32 = "0";
				temp3.bda01 = "8";
				temp3.bef24 = 0;
				temp3.bef15 = $(zhongyaoCom).find(".zhongyao_yszt").val(); //医生嘱托
				temp3.bck01e = $(zhongyaoCom).find(".zhongyao_gyzx select").val(); //给药执行
				bef1.push(temp3);
			}
		}
		//检验
		function GetBefL(tableId,bef1,x) 
		{
			var bck01a = bck01;
			$("#"+tableId+" tbody tr").each(function(i)
			{ 
				count1++;
				var tdArr = $(this);
				var flag =tdArr.find(".jianyan_yznr").val(); //医嘱内容
				if (flag != "" && flag !=undefined)  {
					//医嘱类别
					var zu = tdArr.find(".jianyan_zu").text();
					//检验
					  var temp2 = configData1(tdArr,vaa01,vac01,x);//初始化公共参数
					  temp2.rownr="0";//顺序
					  temp2.bbx01c = tdArr.find(".jianyan_yznr").next().val(); //诊疗项目ID---
					  temp2.bef07 = tdArr.find(".jianyan_yznr").val() //医嘱内容
					  temp2.bef08 = 0;//天数
					  temp2.bef09 = 0;//剂量
					  temp2.bef11 = tdArr.find(".jianyan_zl").val();//数量
					  temp2.bby01 = 0;//收费项目ID
					  temp2.bef13 = tdArr.find(".jianyan_yblx").find("select option:selected").text();//样本
					  temp2.bef16 = tdArr.find(".jianyan_pc").find("select option:selected").text();//频次
					  temp2.bef17 = 1;//次数
					  temp2.bef20 = tdArr.find(".jianyan_zxxz").find("select option:selected").attr("id");//执行性质
					  temp2.bck01 = tdArr.find(".jianyan_zxks").find("select option:selected").val();//执行科室
					  temp2.bef23 = 0;//滴速
					  temp2.vaf59 = zu;//组号
					  temp2.vaf32 = "0";//正常还是给药途径
					  temp2.bda01 = "L";
					  temp2.bef24 = 0;//首次
					  temp2.bef15 = tdArr.find(".jianyan_yszt").val();//医生嘱托
					  
					  bef1.push(temp2);
				}
			});
		}
		
		//检查
		function GetBefE(tableId,bef1,x) 
		{
			var bck01a = bck01;
		    $("#"+tableId+" tbody tr").each(function(i)
			{ 
		    	count1++;
		    	var tdArr = $(this);
				var flag = tdArr.find(".jiancha_yznr").val(); //医嘱内容
				if (flag != "" && flag !=undefined) {
					//医嘱类别
					var bda01 = "E";
					var zu = count1;
					//检查
					  var temp2 = configData1(tdArr,vaa01,vac01,x);//初始化公共参数
					  temp2.rownr="0";//顺序
					  temp2.bbx01c = tdArr.find(".jiancha_yznr").next().val(); //诊疗项目ID---
					  temp2.bef07 = tdArr.find(".jiancha_yznr").val(); //医嘱内容
					  temp2.bef08 = tdArr.find(".jiancha_yyts").val();//天数
					  temp2.bef09 = 0;//剂量
					  temp2.bef11 = tdArr.find(".jiancha_zl").val();//数量
					  temp2.bby01 = 0;//收费项目ID
					  temp2.bef13 = "";//样本
					  temp2.bef16 = tdArr.find(".jiancha_pc").find("select option:selected").text();//频次
					  temp2.bef17 = tdArr.find(".jiancha_yyts").val();//次数
					  temp2.bef20 = tdArr.find(".jiancha_zxxz").find("select option:selected").attr("id");//执行性质
					  temp2.bck01 = tdArr.find(".jiancha_zxks").find("select option:selected").val();//给药科室
					  temp2.bef23 = 0;//滴速
					  temp2.vaf59 = zu;//组号
					  temp2.vaf32 = "0";//正常还是给药途径
					  temp2.bda01 = "E";
					  temp2.bef24 = 0;//首次
					  temp2.bef25 = $(".e_linchuangzhenduan").val();//临床诊断
					  temp2.bef26 = $(".e_fuzhujiancha").val();//辅助检查
					  temp2.bef27 = $(".e_binglizhaiyao").val();//病例摘要/体格检查
					  temp2.bef28 = $(".e_jianchamudi").val();//检查目的
					  temp2.bef15 = tdArr.find(".jiancha_yszt").val();//医生嘱托
					  bef1.push(temp2);
					  var bci07n = tdArr.attr("data-bci07");
					if(bci07n)
					{
						bci07n = JSON.parse(bci07n);
						for(var x = 0;x<bci07n.length;x++)
						{
							var temp3 = configData1(tdArr, vaa01, vac01, x);
							temp3.rownr = x+1+"";
							temp3.bbx01c = tdArr.find(".jiancha_yznr").next().val();
							var vaf22 = tdArr.find(".jiancha_yznr").val().replace(/[\r\n]/g,""); // 医嘱内容
							temp3.bef07 = vaf22.split(":")[0]; // 医嘱内容
							temp3.bef08 = tdArr.find(".jiancha_yyts").val();//天数
							temp3.bef09=0;
							temp3.bef11 = tdArr.find(".jiancha_zl").val();//数量
							temp3.bby01 = 0;
							temp3.bef13 = bci07n[x].bci06;//部位
							temp3.bef14 = replaceAll(replaceAll(bci07n[x].bci07,"<span>",""),"</span>","");//方法
							temp3.bef16 = tdArr.find(".jiancha_pc").find("select option:selected").text();//频次
							temp3.bef17 = tdArr.find(".jiancha_yyts").val();//次数
							temp3.bef20 = tdArr.find(".jiancha_zxxz").find("select option:selected").attr("id");//执行性质
							temp3.bck01 = tdArr.find(".jiancha_zxks").find("select option:selected").val();//给药科室
							temp3.bef23 = 0;//滴速
							temp3.vaf59 = zu;//组号
							temp3.vaf32 = "0";//正常还是给药途径
							temp3.bda01 = "E";
							temp3.bef24 = 0;//首次
							temp3.bef25 = $(".e_linchuangzhenduan").val();//临床诊断
							temp3.bef26 = $(".e_fuzhujiancha").val();//辅助检查
							temp3.bef27 = $(".e_binglizhaiyao").val();//病例摘要/体格检查
							temp3.bef28 = $(".e_jianchamudi").val();//检查目的
							temp3.bef15 = tdArr.find(".jiancha_yszt").val();//医生嘱托
							bef1.push(temp3);
						}
					}
				}
			});
		}
		
		//手术
		function GetBefS(tableId,bef1,x) 
		{
			debugger;
			var bck01a = bck01;
			$("#"+tableId+" tbody").each(function(i)
			{ 
				count1++;
				var tdArr = $(this);
				var flag = tdArr.find(".shoushu_yznr").val();
				if (flag!="" && flag!=undefined) {
					//医嘱类别
					var bda01 = "S";
					var zu = count1;
					
					//主要手术
					  var temp1 = configData1(tdArr,vaa01,vac01,x);//初始化公共参数
					  temp1.rownr="0";//顺序
					  temp1.bbx01c = tdArr.find(".shoushu_yznr").next().val();
					  temp1.bef07 = tdArr.find(".shoushu_yznr").val();
					  temp1.bef08 = 1;//天数
					  temp1.bef09 = 0;//剂量
					  temp1.bef11 = 1;//数量
					  temp1.bby01 = 0;//收费项目ID
					  temp1.bef13 = "";//样本部位
					  temp1.bef16 = tdArr.find(".shoushu_pc").find("select option:selected").text();//频次
					  temp1.bef17 = 1;//次数
					  temp1.bef20 = tdArr.find(".shoushu_zxxz").find("option:selected").attr("id");//执行性质
					  temp1.bck01 = tdArr.find(".shoushu_zxks").find("option:selected").val();//执行科室ID
					  temp1.bef23 = 0;//滴速
					  temp1.vaf59 = zu;//组号
					  temp1.vaf32 = "0";//正常还是给药途径
					  temp1.bda01 = "S";
					  temp1.bef24 = 0;//首次
					  temp1.bef15 = tdArr.find(".shoushu_yszt").val();//医生嘱托
					  temp1.bef14 = tdArr.find(".shoushu_buwei").val();// shoushu_buwei
					  bef1.push(temp1);
					/**
					 * 附加手术医嘱
					 */
					var k = 1;
					$(".shoushu_fjss").each(function(j, ele) {
						if ($(ele).val()) {
							var temp99 = configData1(tdArr,vaa01,vac01,x);//初始化公共参数
							  temp99.rownr=k;//顺序
							  k++;
							  temp99.bbx01c = $(ele).next().val();
							  temp99.bef07 = $(ele).val();
							  temp99.bef08 = 1;//天数
							  temp99.bef09 = 0;//剂量
							  temp99.bef11 = 1;//数量
							  temp99.bby01 = 0;//收费项目ID
							  temp99.bef13 = "";//样本部位
							  temp99.bef16 = "";//频次
							  temp99.bef17 = 1;//次数
							  temp99.bef20 = tdArr.find(".shoushu_zxxz").find("option:selected").attr("id");//执行性质
							  temp99.bck01 = tdArr.find(".shoushu_zxks").find("option:selected").val();//执行科室ID
							  temp99.bef23 = 0;//滴速
							  temp99.vaf59 = zu;//组号
							  temp99.vaf32 = "0";//正常还是给药途径
							  temp99.bda01 = "S";
							  temp99.bef24 = 0;//首次
							  bef1.push(temp99);
						}
					});
					
					//麻醉
//					var mazuiText = tdArr.find(".shoushu_mzfs").find("input:checked").val();
					var mazuiText = tdArr.find(".shoushu_mzfs").find("select").val();
					if (mazuiText!="" && mazuiText!=undefined) {
						var mazuiArr = mazuiText.split("|");
						var temp3 = configData1(tdArr,vaa01,vac01,x);//初始化公共参数
						debugger;
						  temp3.rownr=k + "";//顺序
						  temp3.bbx01c = mazuiArr[1];
//						  temp3.bef07 = tdArr.find(".shoushu_mzfs").find("input:checked").next().text();
						  temp3.bef07 = tdArr.find(".shoushu_mzfs").find("option:selected").text();
						  temp3.bef08 = 1;//天数
						  temp3.bef09 = 0;//剂量
						  temp3.bef11 = 1;//数量
						  temp3.bby01 = 0;//收费项目ID
						  temp3.bef13 = "";//样本部位
						  temp3.bef16 = "";//频次
						  temp3.bef17 = 1;//次数
						  temp3.bef20 = tdArr.find(".shoushu_zxxz").find("option:selected").attr("id");//执行性质
						  temp3.bck01 = tdArr.find(".shoushu_zxks").find("option:selected").val();//执行科室ID
						  temp3.bef23 = 0;//滴速
						  temp3.vaf59 = zu;//组号
						  temp3.vaf32 = "0";//正常还是给药途径
						  temp3.bda01 = "S";
						  temp3.bef24 = 0;//首次
						  bef1.push(temp3);
					}
				}
			});
		}
		
		//治疗
		function GetBefT(tableId,bef1,x)
		{
			var bck01a = bck01;
		    $("#"+tableId+" tbody tr").each(function(i)
			{ 
		    	count1++;
		    	var tdArr = $(this);
				var flag = tdArr.find(".zhiliao_yznr").val(); //医嘱内容
				if (flag != "" && flag !=undefined) {
					//医嘱类别
					var bda01 = "T";
					var zu = count1;
					//检查
					  var temp2 = configData1(tdArr,vaa01,vac01,x);//初始化公共参数
					  temp2.rownr="0";//顺序
					  temp2.bbx01c = tdArr.find(".zhiliao_yznr").next().val(); //诊疗项目ID---
					  temp2.bef07 = tdArr.find(".zhiliao_yznr").val(); //医嘱内容
					  temp2.bef08 = tdArr.find(".zhiliao_ts").val();//天数
					  temp2.bef09 = 0;//剂量
					  temp2.bef11 = tdArr.find(".zhiliao_zl").val();//数量
					  temp2.bby01 = 0;//收费项目ID
					  temp2.bef13 = "";//样本
					  temp2.bef16 = tdArr.find(".zhiliao_pc").find("select option:selected").text();;//频次
					  temp2.bef17 = 1;//次数
					  temp2.bef20 = tdArr.find(".zhiliao_zxxz").find("select option:selected").attr("id");//执行性质
					  temp2.bck01 = tdArr.find(".zhiliao_zxks").find("select option:selected").val();//执行科室ID
					  temp2.bef23 = 0;//滴速
					  temp2.vaf59 = zu;//组号
					  temp2.vaf32 = "0";//正常还是给药途径
					  temp2.bda01 = "T";
					  temp2.bef24 = 0;//首次
					  temp2.bef15 = tdArr.find(".zhiliao_yszt").val();//医生嘱托
					  bef1.push(temp2);
				}
			});
		}
		
		//材料
		function GetBef4(tableId,bef1,x)
		{
			var bck01a = bck01;
			$("#"+tableId+" tbody tr").each(function(i)
					{ 
				count1++;
				var tdArr = $(this);
				var flag = tdArr.find(".cailiao_yznr").val(); //医嘱内容
				if (flag != "" && flag !=undefined) {
					//医嘱类别
					var bda01 = "4";
					var zu = count1;
					//材料
					var temp2 = configData1(tdArr,vaa01,vac01,x);//初始化公共参数
					temp2.rownr="0";//顺序
					temp2.bbx01c = tdArr.find(".cailiao_yznr").next().val(); //诊疗项目ID---
					temp2.bef07 = tdArr.find(".cailiao_yznr").val(); //医嘱内容
					temp2.bef08 = tdArr.find(".cailiao_ts").val();//天数
					temp2.bef09 = 0;//剂量
					temp2.bef11 = tdArr.find(".cailiao_zl").val();//数量
					temp2.bby01 = tdArr.find(".cailiao_yznr").next().next().val();//收费项目ID
					temp2.bef13 = "";//样本
					temp2.bef16 = tdArr.find(".cailiao_pc").find("select option:selected").text();;//频次
					temp2.bef17 = 1;//次数
					temp2.bef20 = tdArr.find(".cailiao_zxxz").find("select option:selected").attr("id");//执行性质
					temp2.bck01 = tdArr.find(".cailiao_zxks").val();//执行科室ID
					temp2.bef23 = 0;//滴速
					temp2.vaf59 = zu;//组号
					temp2.vaf32 = "0";//正常还是给药途径
					temp2.bda01 = "4";
					temp2.bef24 = 0;//首次
					temp2.bef15 = tdArr.find(".cailiao_yszt").val();//医生嘱托
					temp2.bck01e = tdArr.find(".cailiao_gyzx select").val(); //给药执行
					bef1.push(temp2);
				}
					});
		}
		
		/**
		 * 组合vaf1公共基础数据
		 * @param vaa01
		 * @param vac01
		 * @param tableObj
		 * @param i
		 * @returns {___anonymous_vaf1t}
		 */
		function configData1(tdArr,vaa01,vac01,x)
		{
			  var vaf1t = {};
			  vaf1t.bbx01b = "0";//1
			  vaf1t.bef05= "2";//1
			  vaf1t.bef10 = "";//1
			  vaf1t.bef14 = "";//1
			  vaf1t.bef15 = "";//1
			  vaf1t.bef18 = 1;//1
			  vaf1t.bef19 = "";//1
			  vaf1t.bef22 = "";//1
			  vaf1t.bef29 = x;//组
			  return vaf1t;
		}

		
		

/*每一个checkbox添加事件*/
function zlsSlectCheckobx(){
	 /*选择所有*/
	$("#zhiliaoAdvice thead").on('click','[type="checkbox"]',function(e){
	    if($(this).prop('checked')){
	    	$("#zhiliaoAdvice").find('tbody [type="checkbox"]').prop('checked',true);
	    }else{
	    	$("#zhiliaoAdvice").find('tbody [type="checkbox"]').prop('checked',false);
	    }
	});
	$("#zhiliaoAdvice tbody").on('change','[type="checkbox"]',function(e){
		//阻止事件冒泡到tr上
		var evt = e || window.event;
		evt.stopPropagation();
		//1.得到当前的tr
		var $tr = $(this).parents('tr');
		//2.得到所有的tr
		var $trs = $("#zhiliaoAdvice tbody").find('tr');
		//3.得到与当前tr是一组的tr
		var $sameGroupTrs;
		var tr_groupId = $tr.attr('groupid');
		if(tr_groupId){
			$sameGroupTrs = $trs.filter('[groupid='+tr_groupId+']');
		}
		//4.根据checkbox的选中或不选中，
		if($(this).prop('checked')){
			if($sameGroupTrs && $sameGroupTrs.length > 0){
				$sameGroupTrs.each(function(i, ele){
					if(i==0){// tr的第一项中的checkbox已经改变
						return;
					}else{
						$(ele).find('.checkbox-default').prop('checked', true);
					}
				});
			}
		}else{
			if($sameGroupTrs && $sameGroupTrs.length > 0){
				$sameGroupTrs.each(function(i, ele){
					if(i==0){// tr的第一项中的checkbox已经改变
						return;
					}else{
						$(ele).find('.checkbox-default').prop('checked', false);
					}
				});
			}
			$("#zhiliaoAdvice").prop('checked',false);
		}
	});
}

		
		
		
		
		

		
		
		
		